﻿using System.Linq;
using SysConfig = System.Configuration;

namespace FamilyBook.Core.Configuration
{
    public sealed class AppConfig : IConfiguration
    {
        private readonly SysConfig.Configuration _appConfig;

        public AppConfig(SysConfig.Configuration config = null)
        {
            _appConfig = config ?? SysConfig.ConfigurationManager.OpenExeConfiguration(SysConfig.ConfigurationUserLevel.None);
        }
        

        public string DbConnection
        {
            get { return GetAppSettingsValue("DbConnection"); }
        }

        private string GetAppSettingsValue(string key)
        {
            if (_appConfig.AppSettings.Settings.AllKeys.Contains(key))
                return _appConfig.AppSettings.Settings[key].Value;

            return null;
        }
    }
}
